package com.uenpay.im.ui.old.activity.label;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.uenpay.im.R;

import java.util.ArrayList;


/**
 * @author SL
 * @created 2015-12-28 13:37:51
 * @copyRight http://www.qiyunxin.com
 * @function TODO
 */
public class LabelListAdapter extends BaseAdapter {

	private ArrayList<LabelEntity> arrayList = new ArrayList<LabelEntity>();
	private LayoutInflater layoutInflater;

	public LabelListAdapter(Context _Context, ArrayList<LabelEntity> _ArrayLis) {
		this.arrayList = _ArrayLis;
		layoutInflater = LayoutInflater.from(_Context);
	}

	@Override
	public int getCount() {
		return arrayList == null ? 0 : arrayList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arrayList == null ? null : arrayList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		labelViewHodler viewHodler = null;
		LabelEntity labelEntity = arrayList.get(arg0);
		if (arg1 == null) {
			viewHodler = new labelViewHodler();
			arg1 = layoutInflater.inflate(R.layout.item_label_layout, arg2,false);
			viewHodler.nameTv = (TextView) arg1.findViewById(R.id.label_name_tv);
			arg1.setTag(viewHodler);
		} else {
			viewHodler = (labelViewHodler) arg1.getTag();
		}
		viewHodler.nameTv.setText(labelEntity.labelName + "("
				+ labelEntity.arrayList.size() + ")");
		return arg1;
	}

	private class labelViewHodler {
		private TextView nameTv;
	}

}
